package com.yanqu.road.web.controller.inner.activity;

import com.alibaba.fastjson.JSONObject;
import com.yanqu.road.entity.web.activity.GetActivityIdByServerIdReqParam;
import com.yanqu.road.entity.web.activity.GetActivityIdByServerIdRespParam;
import com.yanqu.road.web.mgr.AllActivityMainInfoMgr;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;

@RestController
public class GetActivityIdListByServerId {

    private static Logger logger = LogManager.getLogger(GetActivityIdListByServerId.class.getName());

    @RequestMapping("/getActivityIdListByServerId")
    public Object getActivityIdListByServerId(@RequestBody GetActivityIdByServerIdReqParam param, HttpServletRequest request) {
        GetActivityIdByServerIdRespParam resp = new GetActivityIdByServerIdRespParam();
        if (param.getType() == 1) {
            resp.setActivityIdList(AllActivityMainInfoMgr.getActivityIdListByServerId(param.getServerId(), param.getServerTime()));
        } else if (param.getType() == 2) {
            resp.setActivityIdList(AllActivityMainInfoMgr.getActivityIdListByServerIdAndType(param.getServerId(), param.getTypeList(), param.getServerTime()));
        } else if (param.getType() == 3) {
            return AllActivityMainInfoMgr.getActivityIdListByServerId(param.getServerId());
        } else {
            resp.setActivityIdList(new ArrayList<>());
        }

        logger.info("getActivity time: {}, req: {}, resp {}", new Date(param.getServerTime() * 1000).toString(), JSONObject.toJSONString(param), JSONObject.toJSONString(resp));
        return resp;
    }
}
